require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

desc 'Default: run unit tests.'
task :default => :test

desc 'Test the rquerypad plugin.'
Rake::TestTask.new(:test) do |t|
  t.libs << 'lib'
  t.pattern = 'test/**/*_test.rb'
  t.verbose = true
end

desc 'Generate documentation for the rquerypad plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
  rdoc.rdoc_dir = 'rdoc'
  rdoc.title    = 'Rquerypad'
  rdoc.options << '--line-numbers' << '--inline-source'
  rdoc.rdoc_files.include('README')
  rdoc.rdoc_files.include('lib/**/*.rb')
end

desc 'Create the database defined in config/database.yml for the current RAILS_ENV'
require 'activerecord'
task :migrate  do
  config = {'adapter' => "sqlite3", 'database' => "test/db.rquerypad", 'timeout' => 5000}
  begin
    FileUtils.rm_f(File.dirname(__FILE__) + "/" + config['database'])
  rescue
  end
  begin
    ActiveRecord::Base.establish_connection(config)
    ActiveRecord::Base.connection
  rescue
    `sqlite3 "#{config['database']}"`
  end
  ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/migrate.log")
  ActiveRecord::Migrator.migrate("test/migrate/", 10)
end
